//轮播
var i = 0;
$(function () {
	var timer = null;
	$(".swiper .show li").eq(0).fadeIn(500).siblings().fadeOut(500);
	timer = setInterval(show, 2000)
	$(".swiper .btn li").hover(function () {
		clearInterval(timer);
		i = $(this).index();
		show();
	}, function () {
		timer = setInterval(show, 2000);
	});
});
function show() {
	$(".swiper .show li").eq(i).fadeIn(500).siblings().fadeOut(500);
	$(".swiper .btn li").eq(i).addClass("active").siblings().removeClass("active");
	i++;
	if (i == 5)
		i = 0;
}

// 首页倒计时
function reverseTime(x) {
	// 现在时间
	let now = new Date();
	//    console.log(now);
	now = now.getTime();
	//    console.log(now);
	//未来时间   
	let future = new Date(x);
	future = future.getTime();
	//    console.log(future);
	// 倒计时的毫秒数/1000 = 秒数
	var seconds = (future - now) / 1000;
	//    console.log(seconds);
	// 把得到的秒数转换成天数 小时 分钟 秒
	var day = Math.floor(seconds / 60 / 60 / 24);//天数
	//    console.log(day);
	var seconds = seconds % (60 * 60 * 24);

	var hours = Math.floor(seconds / 60 / 60);//时数
	//    console.log(hours);/
	var seconds = seconds % (60 * 60);

	var minutes = Math.floor(seconds / 60);//分数
	//    console.log(minutes);
	var seconds = parseInt(seconds % 60);//秒数
	//    console.log(seconds);
	if (day < 10) {
		day = ("0" + day);
	}
	if (hours < 10) {
		hours = ("0" + hours);
	}
	if (minutes < 10) {
		minutes = "0" + minutes;
	}
	if (seconds < 10) {
		seconds = "0" + seconds;
	}
	var res = (day + "天" + hours + "时" + minutes + "分" + seconds + "秒");
	// console.log(res);
	res = [day, hours, minutes, seconds];
	return res;
}

//快报
$.post(news_flash_Api, {}, function (data) {
	let str = []
	console.log(data);
	data.forEach(v => {
		console.log(v.title);
		str.push(v.title)
	});
	let arr = str
	console.log(arr);
	window.onload = function () {
		$('.kuaibao span').text(arr[0])
	}
	let n = -1
	function show() {
		if (n + 1 == arr.length) {
			n = -1
		}
		$('.kuaibao').css('position', 'relative')
		//上一个元素移出动画
		$('.kuaibao span').first().animate({
			top: -0.7 + 'rem',
		}, 300, function () {
			$('.kuaibao span').first().remove()
		})
		n++
		//下一个元素添加动画
		$('.kuaibao').append(`<span class='newspan1'>${arr[n]}</span>`)
		$('.newspan1').animate({
			top: 0.1 + 'rem',
		}, 300, function () {
			$('.newspan1').text(arr[n])
		})
	}
	setInterval(show, 2000)
})



// 抢购商品
$.post(buyLimit_Api,{},function(data){
	console.log(data);
})



